Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
resampler_reader.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Roc authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_audio/resampler_reader.h
10//! @brief Resampler.
11
12#ifndef ROC_AUDIO_RESAMPLER_READER_H_
13#define ROC_AUDIO_RESAMPLER_READER_H_
14
15#include "roc_audio/frame.h"
16#include "roc_audio/ireader.h"
17#include "roc_audio/resampler.h"
18#include "roc_audio/units.h"
19#include "roc_core/array.h"
21#include "roc_core/slice.h"
22#include "roc_core/stddefs.h"
23#include "roc_packet/units.h"
24
25namespace roc {
26namespace audio {
27
28//! Resamples audio stream with non-integer dynamically changing factor.
29//! @remarks
30//! Typicaly being used with factor close to 1 ( 0.9 < factor < 1.1 ).
31class ResamplerReader : public IReader, public core::NonCopyable<> {
32public:
33 //! Initialize.
34 //!
35 //! @b Parameters
36 //! - @p reader specifies input audio stream used in read()
37 //! - @p buffer_pool is used to allocate temporary buffers
38 //! - @p frame_size is number of samples per resampler frame per audio channel
39 //! - @p channels is the bitmask of audio channels
41 core::BufferPool<sample_t>& buffer_pool,
42 core::IAllocator& allocator,
43 const ResamplerConfig& config,
45 size_t frame_size);
46
47 //! Check if object is successfully constructed.
48 bool valid() const;
49
50 //! Read audio frame.
51 //! @remarks
52 //! Calculates everything during this call so it may take time.
53 virtual void read(Frame&);
54
55 //! Set new resample factor.
56 //! @remarks
57 //! Resampling algorithm needs some window of input samples. The length of the window
58 //! (length of sinc impulse response) is a compromise between SNR and speed. It
59 //! depends on current resampling factor. So we choose length of input buffers to let
60 //! it handle maximum length of input. If new scaling factor breaks equation this
61 //! function returns false.
62 bool set_scaling(float);
63
64private:
65 bool init_frames_(core::BufferPool<sample_t>&);
66 void renew_frames_();
67
68 Resampler resampler_;
69 IReader& reader_;
70
71 core::Slice<sample_t> frames_[3];
72 const size_t frame_size_;
73 bool frames_empty_;
74
75 bool valid_;
76};
77
78} // namespace audio
79} // namespace roc
80
81#endif // ROC_AUDIO_RESAMPLER_READER_H_
Dynamic array.
Audio frame.
Definition: frame.h:22
Audio reader interface.
Definition: ireader.h:22
Resamples audio stream with non-integer dynamically changing factor.
ResamplerReader(IReader &reader, core::BufferPool< sample_t > &buffer_pool, core::IAllocator &allocator, const ResamplerConfig &config, packet::channel_mask_t channels, size_t frame_size)
Initialize.
bool valid() const
Check if object is successfully constructed.
bool set_scaling(float)
Set new resample factor.
virtual void read(Frame &)
Read audio frame.
Resamples audio stream with non-integer dynamically changing factor.
Definition: resampler.h:48
Memory allocator interface.
Definition: iallocator.h:23
Base class for non-copyable objects.
Definition: noncopyable.h:23
Slice.
Definition: slice.h:23
Audio frame.
uint32_t channel_mask_t
Bitmask of channels present in audio packet.
Definition: units.h:77
Root namespace.
Non-copyable object.
Resampler.
Audio reader interface.
Various units used in audio processing.
Various units used in packets.
Slice.
Commonly used types and functions.
Resampler parameters.
Definition: resampler.h:28